package udp;

import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class Server {
    public static void main(String[] args) throws Exception {
        DatagramSocket socket = new DatagramSocket(3333);
        System.out.println("聊天室开启");
        while (true) {
            DatagramPacket packet = new DatagramPacket(new byte[1024], 1024);
            socket.receive(packet);
            byte[] data = packet.getData();
            String msg = new String(data,0,packet.getLength());
            String ip = packet.getAddress().getHostAddress();
            System.out.println(ip+"发给你了"+msg);
        }


    }
}
